
/* ZIPD CODE DETAILS */


function setPagination(count,topId,downId,topDet,botDet)
{
	//alert(count);
	var perPage = pagination['resultsPerPage'];
	
	if( parseInt(count) > 0 && parseInt(count) > parseInt(perPage) ){
		
		if(topId!=''){
			$('#'+topId).html(pagination['pager']);
		}
		if(downId!=''){
			$('#'+downId).html(pagination['pager']);
		}
		if(topDet!=''){
			$('#'+topDet).html(pagination['resultsDetails']);
		}
		if(botDet!=''){
			$('#'+botDet).html(pagination['resultsDetails']);
		}
	}
	else   {
		if(topId!=''){
			$('#'+topId).html('');
		}
		if(downId!=''){
			$('#'+downId).html('');
		}
		if(topDet!=''){
			$('#'+topDet).html(pagination['resultsDetails']);
		}
		if(botDet!=''){
			$('#'+botDet).html(pagination['resultsDetails']);
		}
	}
}
function setPagination1(count,topId,downId,topDet,botDet)
{
	//alert(count);
	var perPage = pagination1['resultsPerPage'];
	
	if( parseInt(count) > 0 && parseInt(count) > parseInt(perPage) ){
		
		if(topId!=''){
			$('#'+topId).html(pagination1['pager']);
		}
		if(downId!=''){
			$('#'+downId).html(pagination1['pager']);
		}
		if(topDet!=''){
			$('#'+topDet).html(pagination1['resultsDetails']);
		}
		if(botDet!=''){
			$('#'+botDet).html(pagination1['resultsDetails']);
		}
	}
	else   {
		if(topId!=''){
			$('#'+topId).html('');
		}
		if(downId!=''){
			$('#'+downId).html('');
		}
		if(topDet!=''){
			$('#'+topDet).html(pagination1['resultsDetails']);
		}
		if(botDet!=''){
			$('#'+botDet).html(pagination1['resultsDetails']);
		}
	}
}
function getFun(value)
{
	//alert(value);
	$.ajax({
			   
			    type: "POST",
				dataType: "json",
			    data: "photo_id="+value,
			    url: "/album/index/show-comments/",
			    success: function(data){
					$("#listContent").html(data.output);
					$("#bar").html(data.output1);
					viewtag(value);
				
				}
			});

}
/*function getFun(value)
{
	//alert(value);
	$.ajax({
			   
			    type: "POST",
				dataType: "json",
			    data: "photo_id="+value,
			    url: "/album/index/show-comments/",
			    success: function(data){
					$("#listContent").html(data.output);
				pagination = new Array();
				pagination['pages'] = data.pages;
			    pagination['pager'] = data.pager;
			    pagination['currentPage'] = data.currentPage;
			    pagination['resultsPerPage'] = data.resultPerPage;
				pagination['resultsCount'] = data.resultsCount ;
				var requestUrl = "/album/index/pagination/"+value+"/";
				setPagination(pagination['resultsCount'],'','downPagerId','',''); 	
				}

			
		});

} */
function ajaxPager(page,serValue)
{
	//alert(serValue);
	var perPage = pagination['resultsPerPage'];
	//return false;
	 if(serValue=='' || serValue==undefined)
	 {
		//alert(serValue);
		var url = requestUrl + page +  '/' + perPage;
		//alert(serValue);return false;
		
	 } else {
		//serValue = '';
		var url = requestUrl + page +  '/' + perPage+'/' + serValue;
		
	 }
	var perPage = pagination['resultsPerPage'];
	//Eg: var url = '/article/prediction/pagerlist/${article/id}/' + page + '/' + perPage; 
	
	reg = /\s+/;
	//Commented by harinath
	//url = url.replace(reg,'-');

	
	//Eg :  var Params='category=' + $('#prediction_type').val();
	$.getJSON(url,Params, function(data) {
		  $('#listContent').html('<table border="0" width="100%"><tr><td align="center" style="height="400px;"><img src="/images/img_loader.gif" /></td></tr></table>');
		  $('#listContent').html(data.output);
	      pagination['pages'] = data.pages;
	      pagination['pager'] = data.pager;
	      pagination['currentPage'] = data.currentPage;
		  pagination['resultsDetails'] = data.resultsDetails;
		  setPagination(data.resultsCount,'topPagerId','downPagerId',"topdet","botdet"); 
		} );
	 	
}
function ajaxPagerDup(page,serValue)
{
	//alert(serValue);
	var perPage = pagination1['resultsPerPage'];
	//return false;
	if(serValue=='' || serValue==undefined)
	 {
		//alert(serValue);
		var url = requestUrlDup + page +  '/' + perPage;
		//alert(serValue);return false;
		
	 } else {
		//serValue = '';
		var url = requestUrlDup + page +  '/' + perPage+'/' + serValue;
		
	 }
	
	var perPage = pagination1['resultsPerPage'];
	//Eg: var url = '/article/prediction/pagerlist/${article/id}/' + page + '/' + perPage; 
	
	reg = /\s+/;
	url = url.replace(reg,'-');
	//Eg :  var Params='category=' + $('#prediction_type').val();
	$.getJSON(url,Params, function(data) {
		  $('#listAlbums').html('<table border="0" width="100%"><tr><td align="center" style="height="400px;"><img src="/images/img_loader.gif" /></td></tr></table>');
		  $('#listAlbums').html(data.output);
	      pagination1['pages'] = data.pages;
	      pagination1['pager'] = data.pager;
	      pagination1['currentPage'] = data.currentPage;
		  pagination1['resultsDetails'] = data.resultsDetails;
		  setPagination1(data.resultsCount,'topPagerId1','downPagerId1',"topdet","botdet"); 
		} );
	 	
}

function sortingBy(contenttype,bid,pagesize,page,field,order,actionname,urlp)
{
	var fieldorder='ASC',urlPath; 
	if(actionname ==  undefined )
		urlPath = urlp+"index/";
	else
		urlPath = urlp+actionname+"";
	$.ajax({
	type: "POST",
	url: urlPath,
	data: "id="+bid+"&page="+page+"&pagesize="+pagesize+"&field="+field+"&fieldorder="+order,
	success: function(msg){
		$('#postedComments').html(msg);
	}
	});
}

function isValidEmailAddress(emailAddress)
{

var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
}

function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function validInput(string)
{
re=/[<>]/;
return re.test(string);
}

function getObserver()
{
		if(observer == true)
		{
			alert('Functionality of this site is not accessible for your login.');	
			return false;
		} else {
			return true;	
		}
}
function isEmpty(formElement,message) {
	formElement.value = trim(formElement.value);	
	_isEmpty = false;
	if (formElement.value =='') {
		_isEmpty = true;
		jAlert(message);
	//return _isEmpty;
	}
	
	return _isEmpty;
}
function limitText(limitField, limitNum,textMsg) {
    if (limitField.value.length > limitNum) {
		$('#'+textMsg).html('Text too long. Must be '+limitNum+' characters or less');
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
		$('#'+textMsg).html('');
	}
}
